/**
 * 
 */
package com.wskj.library.advice.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wskj.library.pojo.Advice;
import com.wskj.library.service.AdviceService;
import com.wskj.library.service.impl.AdviceServiceImpl;
import com.wskj.util.RequestUtil;
import com.wskj.util.StringUtil;

/**
 * @author 胡洋
 * @describe
 * @Date 2018年3月26日上午11:05:59
 * @version 1.0
 */
@WebServlet(urlPatterns = "/advice/update.do")
public class UpdateAdviceServlet extends HttpServlet {
	AdviceService service=new AdviceServiceImpl(); 
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {	
		
		int id=StringUtil.nullToInt(req.getParameter("id"));
		Advice ad = service.getAdviceById(id);
		req.setAttribute("ad", ad);
		req.getRequestDispatcher("/WEB-INF/page/advice/update.jsp").forward(req, resp);
	
	};

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {			
		Advice advice = RequestUtil.convertRequestToEntity(Advice.class, req);
		
		boolean result = service.updateAdvice(advice);
		resp.sendRedirect(req.getContextPath()+"/advice/list.do");
	};
}
